/**
 * 测试所有状态的按钮显示
 */

import { 
  TASK_STATUS, 
  APPLICANT_STATUS, 
  PUBLISHER_STATUS, 
  USER_ROLE,
  getAvailableActions 
} from "@/constants/taskStatus";

/**
 * 测试所有任务状态的按钮显示
 */
export const testAllTaskStatuses = () => {
  console.log('🧪 测试所有任务状态...\n');
  
  Object.values(TASK_STATUS).forEach(taskStatus => {
    console.log(`📋 任务状态: ${taskStatus}`);
    
    // 测试发布方
    const publisherActions = getAvailableActions(taskStatus, USER_ROLE.PUBLISHER);
    console.log(`  发布方操作: ${publisherActions.join(', ') || '无'}`);
    
    // 测试接单人
    const applicantActions = getAvailableActions(taskStatus, USER_ROLE.APPLICANT);
    console.log(`  接单人操作: ${applicantActions.join(', ') || '无'}`);
    
    console.log('');
  });
};

/**
 * 测试所有接单人状态的按钮显示
 */
export const testAllApplicantStatuses = () => {
  console.log('🧪 测试所有接单人状态...\n');
  
  Object.values(APPLICANT_STATUS).forEach(applicantStatus => {
    console.log(`📋 接单人状态: ${applicantStatus}`);
    
    const actions = getAvailableActions(TASK_STATUS.PAID, USER_ROLE.APPLICANT, applicantStatus);
    console.log(`  操作: ${actions.join(', ') || '无'}`);
    
    console.log('');
  });
};

/**
 * 测试所有发布方状态的按钮显示
 */
export const testAllPublisherStatuses = () => {
  console.log('🧪 测试所有发布方状态...\n');
  
  Object.values(PUBLISHER_STATUS).forEach(publisherStatus => {
    console.log(`📋 发布方状态: ${publisherStatus}`);
    
    const actions = getAvailableActions(TASK_STATUS.PAID, USER_ROLE.PUBLISHER, publisherStatus);
    console.log(`  操作: ${actions.join(', ') || '无'}`);
    
    console.log('');
  });
};

/**
 * 专门测试有纠纷状态
 */
export const testDisputeStatus = () => {
  console.log('🧪 专门测试有纠纷状态...\n');
  
  // 测试发布方有纠纷
  console.log('📋 发布方有纠纷:');
  const publisherDisputeActions = getAvailableActions(
    TASK_STATUS.DISPUTED, 
    USER_ROLE.PUBLISHER, 
    PUBLISHER_STATUS.DISPUTED
  );
  console.log(`  操作: ${publisherDisputeActions.join(', ')}`);
  
  // 测试接单人有纠纷
  console.log('📋 接单人有纠纷:');
  const applicantDisputeActions = getAvailableActions(
    TASK_STATUS.DISPUTED, 
    USER_ROLE.APPLICANT, 
    APPLICANT_STATUS.DISPUTED
  );
  console.log(`  操作: ${applicantDisputeActions.join(', ')}`);
  
  // 验证期望的按钮
  const expectedActions = ['communicate_platform', 'accept_solution', 'reject_solution'];
  
  console.log('\n✅ 验证结果:');
  console.log(`  发布方有纠纷按钮正确: ${expectedActions.every(action => publisherDisputeActions.includes(action))}`);
  console.log(`  接单人有纠纷按钮正确: ${expectedActions.every(action => applicantDisputeActions.includes(action))}`);
  
  console.log('');
};

/**
 * 运行所有测试
 */
export const runAllStatusTests = () => {
  console.log('🚀 开始运行所有状态测试...\n');
  
  testAllTaskStatuses();
  testAllApplicantStatuses();
  testAllPublisherStatuses();
  testDisputeStatus();
  
  console.log('✅ 所有测试完成！');
};

// 如果直接运行此文件，执行所有测试
if (typeof window !== 'undefined' && window.location?.search?.includes('test=true')) {
  runAllStatusTests();
}

export default {
  testAllTaskStatuses,
  testAllApplicantStatuses,
  testAllPublisherStatuses,
  testDisputeStatus,
  runAllStatusTests,
};
